package com.qf.mxapp.service.Impl;

import com.qf.mxapp.mapper.MenuMapper;
import com.qf.mxapp.mapper.ProductMapper;
import com.qf.mxapp.mapper.TagMapper;
import com.qf.mxapp.pojo.Menu;
import com.qf.mxapp.pojo.Product;
import com.qf.mxapp.pojo.Tag;
import com.qf.mxapp.service.MenuService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Resource
    private MenuMapper menuMapper;

    @Resource
    private ProductMapper productMapper;

    @Resource
    private TagMapper tagMapper;

    @Override
    public List<Menu> getMenuList() {
        List<Menu> list_menu = menuMapper.queryMenuListByState(0);
        for (Menu menu : list_menu) {
            List<Product> list_product = productMapper.querByMenuId(menu.getId());
            for (Product product : list_product) {
                List<Tag> list_tag = tagMapper.QueryByProId(product.getId());
                product.setTagList(list_tag);
            }
            menu.setProductList(list_product);
        }
        return list_menu;
    }

    @Override
    public Menu getMenuById(int id) {
        Menu menu = menuMapper.selectByPrimaryKey(id);
        List<Product> productList = productMapper.querByMenuId(menu.getId());
        for (Product product : productList) {
            List<Tag> list_tag = tagMapper.QueryByProId(product.getId());
            product.setTagList(list_tag);
        }
        menu.setProductList(productList);
        return menu;
    }

}
